package com.netstar.salesman_90dsp.activity;

import java.util.Date;

import org.joda.time.DateTime;

import roboguice.inject.InjectView;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.netstar.salesman_90dsp.R;
import com.netstar.salesman_90dsp.TitleBaseActivity;
import com.netstar.salesman_90dsp.tool.DialogTool;
import com.squareup.timessquare.CalendarPickerView;
import com.squareup.timessquare.CalendarPickerView.OnDateSelectedListener;

/**
 * 日历选择页面
 * 
 * @author zhangshuai
 * 
 */
public class TodayWorkCalendarActivity extends TitleBaseActivity {
	/**
	 * 日期选择 dialog，布局view
	 */
	@InjectView(DialogTool.VIEW_ID_CALENDAR)
	private CalendarPickerView calendarPickerView;
	/**
	 * 最小日期
	 */
	private DateTime dateTimeMin = DateTime.now().minusYears(2);
	/**
	 * 最大日期
	 */
	private DateTime dateTimeMax = DateTime.now().plusYears(2);
	/**
	 * 当前日期
	 */
	private DateTime dateTimeCurrent = DateTime.now();

	@Override
	public void subInitContentView(Bundle savedInstanceState) {
		setContentView(R.layout.activity_today_work_calendar);
	}

	@Override
	public void subInitView() {
		// 设置title
		include_title_tv_activity_name.setVisibility(View.VISIBLE);
		include_title_tv_activity_name
				.setText(R.string.activity_today_work_title_add);
		include_title_bt_right.setVisibility(View.GONE);
		include_title_bt_left.setVisibility(View.VISIBLE);
		include_title_bt_left.setText(R.string.common_text_back);
		include_title_bt_right.setText(R.string.common_text_gointo);

	}

	@Override
	public void subInitParam() {
		// 初始化日期时间
		calendarPickerView.init(dateTimeMin.toDate(), dateTimeMax.toDate());
		calendarPickerView.selectDate(dateTimeCurrent.toDate());
		calendarPickerView
				.setOnDateSelectedListener(new OnDateSelectedListener() {
					DateTime selectDate = null;

					@Override
					public void onDateUnselected(Date date) {
						// TODO Auto-generated method stub

					}

					@Override
					public void onDateSelected(Date date) {
						Intent intent = new Intent();
						intent.setClass(activityContext,
								TodayWorkActivity.class);
						intent.putExtra(
								TodayWorkActivity.INTENT_KEY_APPOINT_DATE,
								new DateTime(date)
										.toString(getResources()
												.getString(
														R.string.common_format_date_time)));
						startActivity(intent);
					}
				});
	}

	@Override
	public void subSetOnclick() {
		setOnclickWithDefaultListener(include_title_bt_left);
		setOnclickWithDefaultListener(include_title_bt_right);
	}

	@Override
	public void subRunSomeThing() {

	}

	@Override
	public void callbackWithDefaultListener(View view) {
		super.callbackWithDefaultListener(view);
		switch (view.getId()) {
		case R.id.include_title_bt_left:
			// 返回按钮
			finish();
			break;
		case R.id.include_title_bt_right:
			// 进入按钮
			Intent intent = new Intent();
			intent.setClass(activityContext, TodayWorkActivity.class);
			intent.putExtra(TodayWorkActivity.INTENT_KEY_APPOINT_DATE,
					new DateTime(calendarPickerView.getSelectedDate())
							.toString(getResources().getString(
									R.string.common_format_date)));
			startActivity(intent);
			break;

		default:
			break;
		}
	}

}
